package com.linyu.dislockluaredisboot.config;

import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;

/**
 * @author 23087
 */
@Configuration
public class RedisConfigs {

    @Value("${spring.redis.host}")
    private String redisHost;

    @Value("${spring.redis.port}")
    private Integer redisPort;

    /**
     * 配置连接池
     * 用于编写 Lua 脚本
     * @return
     */
    @Bean
    public JedisPool jedisPool(){
        return new JedisPool(redisHost,redisPort);
    }

    @Bean
    public Redisson redisson(){
        Config config = new Config();
        config.useSingleServer()
                .setAddress(redisHost+":"+redisPort)
                .setDatabase(0);
        return (Redisson) Redisson.create(config);
    }

}
